import tkinter as tk
from tkinter import filedialog
from tkinterdnd2 import TkinterDnD, DND_FILES
import hashlib


def calculate_md5(file_path):
    hash_md5 = hashlib.md5()
    with open(file_path, "rb") as f:
        for chunk in iter(lambda: f.read(4096), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()

def on_drop(event):
    # 获取拖放的文件路径
    file_path = event.data.strip('{}')
    # 计算并显示MD5值
    md5_value = calculate_md5(file_path)
    result_label.config(text=f"File: {file_path}\nMD5: {md5_value}\n微信公众号关注“听说爱情很美”\n\n作者QQ:2693970926(工作使用)", fg="green")

def open_file_dialog():
    file_path = filedialog.askopenfilename()
    if file_path:
        md5_value = calculate_md5(file_path)
        result_label.config(text=f"File: {file_path}\n\n\nMD5: {md5_value}\n\n微信公众号关注“听说爱情很美”\n\n作者QQ:2693970926(工作使用)", fg="green")

# 创建主窗口
root = TkinterDnD.Tk()
root.title("一夕千念_MD5查看器,微信公众号关注“听说爱情很美”")

# 设置窗口初始大小
root.geometry("500x300")  # 宽500，高300

# 设置窗口最小和最大尺寸
root.minsize(400, 200)
root.maxsize(800, 600)

# 创建标签显示结果
result_label = tk.Label(root, text="将文件拖拽进来，或者点击下面的‘打开文件’", fg="black")
result_label.pack(pady=20)

# 创建打开文件按钮
open_file_button = tk.Button(root, text="打开文件", command=open_file_dialog)
open_file_button.pack(pady=10)

# 绑定拖放事件
root.drop_target_register(DND_FILES)
root.dnd_bind('<<Drop>>', on_drop)

# 运行主循环
root.mainloop()
